package com.test.daily.leetcode.y2022.m07.day0718.v03;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/7/18 下午 04:56
 * @version: 1.0
 */
public class Solution {
    public static class Node{
        Node left;
        Node right;
        int value;
        public Node(int value){
            this.value = value;
        }
    }
    public void preSerial(Node root){
        Queue<String> queue = new LinkedList<>();
        pre(root, queue);

    }
    public void pre(Node root, Queue<String> queue){
        queue.add(String.valueOf(root.value));
        if(root.left != null){
            pre(root.left, queue);
        }
        if(root.right != null){
            pre(root.right, queue);
        }
    }
    public Node deSerial(Queue<String> queue){
        return dePre(queue);
    }
    public Node dePre(Queue<String> queue){
        String val = queue.poll();
        int value = Integer.valueOf(val);
        Node head = new Node(value);
        head.left = dePre(queue);
        head.right = dePre(queue);
        return head;
    }
}
